import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;

import dacp.etl.kafka.steam.Chain;

public class Stream {
	static String ori = "|712|5|0000000a27d5c3acc25e20ae597d37ff|6|460025071280390|3594540725330202|18327663707|20|1501378581109|1501378581118|0|20|65535|0|255|255|255|1509965509|65535|255|4294967295|807|194|3709900622|4294967295|171177928|4294967295|4294967295|4294967295|4294967295|4294967295|42949672954294967295|1682962441|4294967295|4294967295|4294967295|1682942053|36412|36412|29101|77549443|65535|4294967295|cmnet.mnc002.mcc460.gprs|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|18327663707|460025071280390|3594540725330202|35945407|712|1501378581|1501378581|65535|18446744073709551615|4294967295|255|255|109|118|255";

	static int count = 1000000;
	static Splitter sp = Splitter.on('|');
	static Joiner jo = Joiner.on('|');

	public static void main(String[] args) {
		Date date = new Date(1501378581109L);
		String format = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
		System.out.println(format);

		DateTime dateTime = new DateTime(1501378581109L);
		DateTimeFormatter forPattern = DateTimeFormat.forPattern("yyyyMMddHHmmss");
		System.out.println(dateTime.toString(forPattern));
		/*
		Chain build = Chain.build(new Integer[] { 5, 7, 9, 41, 42 }, new Integer[] { 9, 10 }, new Integer[] { 7 });

		System.out.println(build);
		ori = "|27|5|00000011d119352196b23d03599d4481|6|460001843768295|3558270805016209|15972302586|4|1503478913004|1503478918631|0|65535|65535|1|255|255|255|477063397|65535|255|4294967295|804|150|3530528011|4294967295|168547120|4294967295|4294967295|4294967295|4294967295|4294967295|4294967295|4294967295|1682962449|4294967295|4294967295|4294967295|1682911969|36412|36412|29192|113480194|65535|4294967295|cmnet.mnc000.mcc460.gprs|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|15972302586|460001843768295|3558270805016209|35582708|27|1503478913|1503478918|65535|18446744073709551615|4294967295|2|255|4|631|255";

		System.out.println(ori.split("\\|")[5]);
		System.out.println(build.process(ori));

		build = Chain.build(new Integer[] { 9, 5, 7, 41, 42 }, new Integer[] { 9, 10 }, new Integer[] { 7 });

		System.out.println(build);
		
		System.out.println(build.process(ori));
		*/
	}

	public static void t2(String[] args) {
		String[] split = ori.split("\\|");

		count = 2;

		long b2 = System.currentTimeMillis();
		for (int i = 0; i < count; i++) {
			StringBuffer stringBuffer = new StringBuffer();
			for (String s : split) {
				stringBuffer.append(s);
				stringBuffer.append("|");
			}
			stringBuffer.deleteCharAt(stringBuffer.length() - 1);
			String string = stringBuffer.toString();

			System.out.println(string);
		}
		System.out.println(System.currentTimeMillis() - b2);

		long b1 = System.currentTimeMillis();
		for (int i = 0; i < count; i++) {
			String string = jo.join(split);
			System.out.println(string);
		}
		System.out.println(System.currentTimeMillis() - b1);
	}

	public static void t1(String[] args) {
		int[] inx = new int[] { 4, 5, 6, 7, 8 };

		long b2 = System.currentTimeMillis();
		for (int i = 0; i < count; i++) {
			ArrayList<Object> newArrayList = Lists.newArrayList();
			String[] split = ori.split("\\|");
			for (int x : inx) {
				newArrayList.add(split[x]);
			}
			// System.out.println(jo.join(newArrayList));
		}

		System.out.println(System.currentTimeMillis() - b2);

		long b1 = System.currentTimeMillis();
		for (int i = 0; i < count; i++) {
			Iterable<String> split = sp.split(ori);
			Iterator<String> iterator = split.iterator();
			int k = 0;
			int kk = 0;

			int nowinx = inx[kk];
			ArrayList<Object> newArrayList = Lists.newArrayList();
			while (iterator.hasNext()) {
				String next2 = iterator.next();

				if (k == nowinx) {
					newArrayList.add(next2);
					kk++;
					if (kk == inx.length) {
						break;
					}
					nowinx = inx[kk];
				}
				k++;
			}
			// System.out.println(jo.join(newArrayList));
		}

		System.out.println(System.currentTimeMillis() - b1);

	}
}
